package com.xtpt.disaster.controller;

import com.xtpt.disaster.common.PortalResult;
import com.xtpt.disaster.common.PropertyConfig;
import com.xtpt.disaster.service.TestService;
import com.xtpt.disaster.utils.ServerPathUtil;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 示例
 * SWAGGER UI 访问地址：http://localhost:8080/swagger-ui.html
 * 集成flyway，提供数据库版本控制，自动初始化数据库
 */
@RestController
@RequestMapping("/rest/test/")
public class TestController {

    @Autowired
    TestService testService;

    @Autowired
    PropertyConfig config;
    @Autowired
    ServerPathUtil util;

    @ApiOperation(value = "查询测试接口",tags = {"查询接口"})
    @RequestMapping(value = "/all", method = RequestMethod.GET)
    public PortalResult getAllTest(){

        return PortalResult.ok(testService.getAll());
    }

    @ApiOperation(value = "根据ID查询",tags = {"ID查询"})
    @RequestMapping(value = "/get", method = RequestMethod.GET)
    public PortalResult getById(@ApiParam(name="id",value = "查询id",required = true) Integer id){
        return PortalResult.ok(testService.getById(id));
    }

    @RequestMapping(value = "/serverpath", method = RequestMethod.GET)
    public PortalResult serverpath(){
        String fileServerPath = util.getFileServerPath("123","test.txt");  //
        String dbServerPath = util.getDBServerPath("123","test.txt",0,"back");
        Map<String,String> map = new HashMap<String,String>();
        map.put("fileServerPathExample",fileServerPath);
        map.put("dbServerPathExample",dbServerPath);

        return PortalResult.ok(map);
    }
}
